<?php
namespace app\index\validate;

use think\Validate;

class Reg extends Validate
{
    protected $rule = [
        'agreement'  => 'require',
        'captcha'=>'require|captcha|checkrepeat',
        'password'=>'require|length:6,20',
        'repassword'=>'require|confirm:password',
        'username'=>'require|regex:[a-z]\w{6,8}|unique:user',
        'phone'=>'require|regex:1\d{10}|unique:user'
    ];

    protected $message = [
        'agreement.require'  => '服务必须同意',
        'password.length'=>'密码必须6-20位',
        'repassword.confirm'=>'两次密码不一致',
        'username.unique'=>'昵称已昵称',
        'phone.unique'=>'手机已经被使用'
    ];

     protected $scene = [
        'login'  =>  ['captcha'],
        'msg'=>['captcha','phone'],
    ];

    public function checkrepeat($v,$rule,$data)
    {
        if(!isset($data['password'])){

            $msginfo = session('msginfo');

            if($msginfo && time()-$msginfo['ctime']<60){
                    return "一分钟之内不能重复发";
            }
        }

        return true;
    }

}